package org.boun.swe.ARCEONE;

import java.util.List;
import java.util.Locale;

import org.boun.swe.ARCEONE.Data.ViolationGeoPoint;
import org.boun.swe.ARCEONE.Static.Constants;
import org.boun.swe.ARCEONE.Utility.JSONManager;
import org.boun.swe.ARCEONE.Utility.ViolationPinpoint;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.MapView.LayoutParams;  
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;

public class ClickedCoordinateActivity extends MapActivity {
    MapView mapView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.clicked_coordinate);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.add(mapOverlay);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    private class MapOverlay extends Overlay
    {
        @Override
        public boolean onTouchEvent(MotionEvent event, MapView mapView)
        {
            //---when user lifts his finger---
            if (event.getAction() == 1) {
            	GeoPoint mapCenter = mapView.getMapCenter();
            	float centerLatitude = (float)(mapCenter.getLatitudeE6())/1000000;
                float centerLongitude = (float)(mapCenter.getLongitudeE6())/1000000;
            	
            	
            	GeoPoint mapTopLeft = mapView.getProjection().fromPixels(0, 0);
            	float topLatitude = (float)(mapTopLeft.getLatitudeE6())/1000000;
            	float leftLongitude = (float)(mapTopLeft.getLongitudeE6())/1000000;
            	
            	GeoPoint mapBottomRight
            	   = mapView.getProjection().fromPixels(mapView.getWidth(), mapView.getHeight());
            	   float bottomLatitude = (float)(mapBottomRight.getLatitudeE6())/1000000;
            	   float rightLongitude = (float)(mapBottomRight.getLongitudeE6())/1000000;

            	String info =
            	     "Center: " + centerLatitude + "/" + centerLongitude + "\n"
            	     + "Top Left: " + topLatitude + "/" + leftLongitude + "\n"
            	     + "Bottom Right: " + bottomLatitude + "/" + rightLongitude + "\n"
            	     ;
            	
            	Toast.makeText(ClickedCoordinateActivity.this,
            		     info,
            		     Toast.LENGTH_LONG).show();

               
            }
            return false;
        }
    }
}